package com.java2007.hotel.utils;

public class PageSupport {
	//当前页码-来自于用户输入
	private int currentPageNo = 1;
	
	//总数量（表）
	private int totalCount = 0;
	
	//页面容量
	private int pageSize = 6;
	private int totalPageCount = 1;

	public void setCurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPageNo() {
		return currentPageNo;
	}

	public PageSupport(int totalCount, int currentPageNo){

		if(totalCount > 0){
			this.totalCount = totalCount;
		}

		if(pageSize > 0){
			this.pageSize = pageSize;
		}

		if (this.getTotalPageCount() ==0){
			this.totalPageCount = 1;
		}else {
			this.totalPageCount = this.getTotalPageCount();
		}

		if(currentPageNo > this.totalPageCount){
			this.currentPageNo = this.getTotalPageCount();
		}else if(currentPageNo <= this.totalPageCount && currentPageNo >0){
			this.currentPageNo = currentPageNo;
		}else {
			this.currentPageNo = 1;
		}

	}

	public int getStartCount() {
			return (currentPageNo - 1) * pageSize;
	}

	
	public  int getTotalPageCount(){
		if(this.totalCount % this.pageSize == 0){
			return this.totalCount / this.pageSize;
		}else if(this.totalCount % this.pageSize > 0){
			return this.totalCount / this.pageSize + 1;
		}else{
			return 0;
		}
	}

	public  int getPageSize(){
		return  this.pageSize;
	}


	
}